package com.szbmyoubao.app.view.tab

import android.annotation.SuppressLint
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatCheckedTextView
import com.ellecity06.cwhiskymall.R
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView

/**
 * @author ellecity06
 * @time 2024/10/24 19:00
 * @des
 */
@SuppressLint("ViewConstructor")
class CommonTab(context: Context, list: List<String>, index: Int) : LinearLayout(context),
    IPagerTitleView {
    private val tvTitle: AppCompatCheckedTextView by lazy { findViewById(R.id.tv_title) }

    init {
        orientation = VERTICAL
        gravity = Gravity.CENTER
//        addView(titleView)
        LayoutInflater.from(context).inflate(R.layout.item_home_menu_tab, this, true)
        val item = list[index]
        tvTitle.text = item
        checkItem(index == 0)

    }

    private fun checkItem(b: Boolean) {
        tvTitle.isChecked = b

    }

    override fun onSelected(index: Int, totalCount: Int) {
        checkItem(true)
    }

    override fun onDeselected(index: Int, totalCount: Int) {
        checkItem(false)
    }

    override fun onLeave(index: Int, totalCount: Int, leavePercent: Float, leftToRight: Boolean) {
    }

    override fun onEnter(index: Int, totalCount: Int, enterPercent: Float, leftToRight: Boolean) {
    }
}